<?php
session_start();

$username="root";
$database="cs4400_group17";

$Email=$_SESSION['userEmail'];
$Title=$_POST['title'];
$Url=$_POST['url'];
$desc=$_POST['desc'];
$tags = $_POST['tags'];

$tagsArray = explode(",",$tags);


mysql_connect('localhost',$username);
@mysql_select_db($database) or die( "Unable to select database");

$DT = date("Y-m-d H:i:s");

$query = "INSERT INTO PushPin VALUES('$Email','$Title','$Url','$DT','$desc')";
mysql_query($query);

foreach($tagsArray as $aTag){
	$aTag = trim($aTag);
	$query2 = "INSERT INTO Tags VALUES('$Url','$aTag')";
	mysql_query($query2);
}

mysql_close();
?>

<!DOCTYPE html>
<head>
</head>
<body>
	<p>Pushpin successfully added!</p>
	<form action='ViewPushpin.php' method='post'>
		<input type="hidden" name="pushpinEmail" value="<?php echo $Email;?>"/>
		<input type="hidden" name="pushpinURL" value="<?php echo $Url;?>"/>
		<input type="hidden" name="pushpinTitle" value="<?php echo $Title;?>"/>
		<input type="hidden" name="pushpinDateTime" value="<?php echo $DT;?>"/>
		<input type="hidden" name="pushpinDescription" value="<?php echo $desc;?>"/>
		<input type="submit" value="View my new Pushpin Now!"/>
	</form>
</body>
</html>